package iqq.ui.view.window;

import iqq.ui.widget.TitleComponent;
import iqq.util.SystemUtils;

import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import java.awt.Image;

import com.alee.laf.rootpane.WebFrame;

/**
 * BaseFrame
 * 
 * @author ChenZhiHui
 * @create-time 2013-3-6
 */
public class BaseFrame extends WebFrame {

	private static final long serialVersionUID = -6482382770685909615L;
	
	private Image iconImage;
	
	private TitleComponent titleComponent;
	
	public BaseFrame() throws HeadlessException {
		super();
		init(null);
	}

	public BaseFrame(GraphicsConfiguration gc) {
		super(gc);
		init(null);
	}

	public BaseFrame(String title) throws HeadlessException {
		super(title);
		init(title);
	}

	public BaseFrame(String title, GraphicsConfiguration gc) {
		super(title, gc);
		init(title);
	}

	/**
	 * 初始化窗口
	 */
	public void init(String title) {
		titleComponent = new TitleComponent(title, this);
		
		this.setShowTitleComponent(false);
		this.setShowWindowButtons(false);
		this.setShadeWidth(30);
		this.getRootPane().getContentPane()
				.add(titleComponent, BorderLayout.PAGE_START);
		
		/**
		 * 解决LINUX兼容问题
		 */
		if (SystemUtils.isLinux()) {
			this.setUndecorated(true);
		}
	}

	/**
	 * @return the iconImage
	 */
	public Image getIconImage() {
		return iconImage;
	}

	/**
	 * @param iconImage the iconImage to set
	 */
	public void setIconImage(Image iconImage) {
		this.iconImage = iconImage;
		super.setIconImage(iconImage);
		titleComponent.setTitleIcon(iconImage);
	}

}
